<?php

namespace app\api\controller;

use app\api\model\Record as RecordModel;
use app\Request;

class Records
{
  public function index(Request $request)
  {
      $params = $request->post();
      $recordModel = new RecordModel();
      $records = $recordModel->getAll($params);
      return show($records);
  }

    public function show(Request $request) {
        $id = $request->param('id');
        $recordModel = new RecordModel();
        $record = $recordModel->getOne($id);
        return show($record);
    }

    public function add(Request $request) {
      $params = $request->post();
      $recordModel = new RecordModel();
      $record = $recordModel->saveOne($params);
      return json($record);
    }

    public function update(Request $request) {
      $params = $request->post();
      $recordModel = new RecordModel();
      $bool = $recordModel->updateOne($params);
      if ($bool) {
          return message('修改成功');
      } else {
          return message('修改失败', 201);
      }
    }

    public function destroy(Request $request) {
        $id = $request->param('id');
        $recordModel = new RecordModel();
        $bool = $recordModel->deleteOne($id);
        return json($bool);
    }
}
